// SQLServerCombo.cpp : implementation file
//

#include "stdafx.h"
#include "AUSlotsTester.h"
#include "SQLServerCombo.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSQLServerCombo

CSQLServerCombo::CSQLServerCombo()
{
}

CSQLServerCombo::~CSQLServerCombo()
{
}


BEGIN_MESSAGE_MAP(CSQLServerCombo, CComboBox)
	//{{AFX_MSG_MAP(CSQLServerCombo)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSQLServerCombo message handlers

void CSQLServerCombo::Load()
{
	CWaitCursor wait;

	ResetContent();

	AddString( _T("(local)") );

	CComPtr<_Application> pDMOApp;

	if ( SUCCEEDED( pDMOApp.CoCreateInstance( CLSID_Application ) ) )
	{
		CComPtr<NameList> pNameList;

		if ( SUCCEEDED( pDMOApp->ListAvailableSQLServers( &pNameList ) ) )
		{
			long nCount = 0;

			pNameList->GetCount( &nCount );

			for( long n = 0; n < nCount; n++ )
			{
				CComBSTR bstrName;
				CComVariant var;

				var = n;

				pNameList->Item( var, &bstrName );
		
				CString str = bstrName;

				if ( !str.IsEmpty() && str != _T("(local)") )
				{
					AddString( str );
				}
			}
		}
	}
}
